package com.web44.springmvc.web;

import com.web44.springmvc.bean.User;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @Title: StudentController
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/1/15 9:16
 */
@RestController
@RequestMapping("stu")
public class StudentController {

    @GetMapping("params01")
    public String queryParams01(String name,double score) {
        System.out.println("参数1："+name);
        System.out.println("参数2："+score);
         return "普通参数";
    }

    @GetMapping("params02")
    public String queryParams02(@RequestParam("user") String name,@RequestParam(
            value = "score",
            required = true,
            defaultValue = "100"
    )
    double score) {
        System.out.println("参数1："+name);
        System.out.println("参数2："+score);
        return "普通参数";
    }

    @PostMapping("params03")
    public String queryParams03(User user) {
        System.out.println("参数1："+user);
        return "pojo";
    }

    @PostMapping("params04")
    public String queryParams04(String[] arrs) {
        System.out.println("参数1："+ Arrays.toString(arrs));
        return "array";
    }

    @PostMapping("params05")
    public String queryParams05(@RequestParam List<String> list) {
        System.out.println("参数1："+ list);
        return "list";
    }

    @PostMapping("json01")
    public String queryJson01(@RequestBody String[] array) {
        System.out.println(array);
        return "json array";
    }

    @PostMapping("json02")
    public String queryJson02(@RequestBody List<String>  list) {
        System.out.println(list);
        return "json array";
    }

    @PostMapping("json03")
    public String queryJson03(@RequestBody User user) {
        System.out.println(user);
        return "json user";
    }

    @PostMapping("json04")
    public String queryJson04(@RequestBody List<User> users) {
        System.out.println(users);
        return " json list user";
    }

    @PostMapping("date01")  // 默认匹配就是 2023/11/12
    public String queryDate01(Date date) {
        System.out.println(date);
        return " json  date";
    }

    // @DateTimeFormat 格式化日期注解
    // 配置了全局类型转换器 会将其覆盖掉
    @PostMapping("date02")  // 默认匹配就是 2023/11/12
    public String queryDate02(@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss") Date date) {

        System.out.println(date);
        return " json  date02";
    }
}
